<template>
  <div class="app-container">
    <el-form label-width="120px" :model="qualityPredictPojo">
<!--      <h5>基本信息</h5>-->
      <el-row>
        <el-col :span="12">
          <el-form-item label="单据编号" prop="documentNumber">
            <el-input v-model="qualityPredictPojo.documentNumber" :disabled="true" maxlength="30" style="width:240px"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="用工日期" prop="predictTime">
            <el-date-picker
              v-model="qualityPredictPojo.predictTime"
              size="mini"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="date"
              :picker-options="pickerOptions"
              placeholder="选择日期">

            </el-date-picker>
          </el-form-item>
          <!--          <el-form-item label="预测时间" prop="predictTime">-->
          <!--            <el-input v-model="qualityPredictPojo.predictTime" maxlength="30"/>-->
          <!--          </el-form-item>-->
        </el-col>

      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="所在岗位" prop="fillInUserPost" v-show="false">
            <el-input v-model="qualityPredictPojo.fillInUserPost" :disabled="true"  maxlength="30"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所在部门" prop="fillInUserDept" v-show="false">
            <el-input v-model="qualityPredictPojo.fillInUserDept" :disabled="true"   maxlength="30"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark" v-show="false">
            <el-input v-model="qualityPredictPojo.remark" maxlength="30"/>
          </el-form-item>
        </el-col>
      </el-row>
<!--      <h5>预测信息</h5>-->
      <el-row>
        <el-col :span="12">
          <el-form-item label="填写人员" prop="fillInName" v-show="false">
            <el-input v-model="qualityPredictPojo.fillInName" :disabled="true"  maxlength="30"/>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="预测班次" prop="predictTime">
          <el-select ref="selectValue1" v-model="qualityPredictPojo.predictTimeShift" filterable placeholder="请选择" value-key="id" @change="currentSel" style="width:240px">
            <el-option
              v-for="item in operationNeedList"
              :key="item.id"
              :label="item.name"
              :value="item"
            />
          </el-select>
          </el-form-item>
<!--          <el-form-item label="预测班次" prop="predictTimeShift">-->
<!--            <el-input v-model="qualityPredictPojo.predictTimeShift" maxlength="30"/>-->
<!--          </el-form-item>-->
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="预测24h" prop="future24PredictNumber">
            <el-input  v-model="qualityPredictPojo.future24PredictNumber" maxlength="30" style="width:240px">
            <i slot="append" style="margin-right: 10px">万件</i>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="预测12h" prop="future12PredictNumber">
            <el-input  v-model="qualityPredictPojo.future12PredictNumber" maxlength="30" style="width:240px">
            <i slot="append" style="margin-right: 10px">万件</i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
<!--        <el-col :span="12">
          <el-form-item label="预测量（万件）" prop="predictNumber">
            <el-input  v-model="qualityPredictPojo.predictNumber" maxlength="30"/>
          </el-form-item>
        </el-col>-->
        <el-col :span="12">
          <el-form-item label="省内未发" prop="provinceNotIssued">
            <el-input  v-model="qualityPredictPojo.provinceNotIssued" maxlength="30" style="width:240px">
            <i slot="append" style="margin-right: 10px">万件</i>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="车辆数" prop="carNumber">
            <el-input  v-model="qualityPredictPojo.carNumber" maxlength="30" @input="onInput()"  style="width:240px">
              <i slot="append" style="margin-right: 10px">辆</i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>

        <el-col :span="12">
          <el-form-item label="待卸量" prop="unloadedNumber">
            <el-input  v-model="qualityPredictPojo.unloadedNumber" maxlength="30" style="width:240px">
              <i slot="append" style="margin-right: 10px">万件</i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
<!--      <el-card class="box-card" style="margin-top: 20px">-->
<!--        <div slot="header" class="clearfix">-->
<!--          <span>附件</span>-->
<!--        </div>-->
<!--        <div style="max-width: 500px">-->
<!--          <el-upload-->
<!--            :limit="2"-->
<!--            class="upload-annex"-->
<!--            :headers="upload.headers"-->
<!--            :action="upload.url"-->
<!--            :on-change="handleUploadChange"-->
<!--            :on-remove="handleUploadRemove"-->
<!--            :file-list="fileList">-->
<!--            <el-button size="small" type="primary">上传文件</el-button>-->
<!--            <div slot="tip" class="el-upload__tip">最多上传两个附件</div>-->
<!--            <div slot="tip" class="el-upload__tip">支持扩展名：.rar .zip .doc .docx .pdf .jpg</div>-->
<!--          </el-upload>-->
<!--        </div>-->

<!--      </el-card>-->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="addQualityPredict">提 交</el-button>
    </div>
  </div>
</template>

<script>
  import { viewTimeShift , viewUserData , addQualityPredict} from "@/api/job/qualityPredict/qualityPredict";
  import {getToken} from "@/utils/auth";
  export default {
    name: "qualityPredict",
    created() {
       this.viewUserData();
       this.viewTimeShift();
    },
    data() {
      return {
        pickerOptions:{
          disabledDate(date) {
            //disabledDate 文档上：设置禁用状态，参数为当前日期，要求返回 Boolean
            return date.getTime() < Date.now() - 24 * 60 * 60 * 1000;
          }
        },
        upload:{
          // 设置上传的请求头部
          headers: {Authorization: "Bearer " + getToken()},
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/common/upload"
        },
        //附件文件列表
        fileList: [],
        operationNeedList: [],
        // 是否显示弹出层（数据权限）
        openDataScope: false,
        menuExpand: false,
        menuNodeAll: false,
        deptExpand: true,
        deptNodeAll: false,
        qualityPredictPojo:{},
        defaultProps: {
          children: "children",
          label: "label",
        },
      };
    },

    methods: {
      viewUserData() {
        viewUserData().then(es => {
          this.qualityPredictPojo = es.data;
        })
      },
      viewTimeShift() {
        viewTimeShift().then(es => {
          this.operationNeedList = es.data;
        })
      },
      addQualityPredict() {
        let predictTime = this.qualityPredictPojo.predictTime;
        let predictTimeShift = this.qualityPredictPojo.predictTimeShift;
        let future24PredictNumber = this.qualityPredictPojo.future24PredictNumber;
        let future12PredictNumber = this.qualityPredictPojo.future12PredictNumber;
        let provinceNotIssued = this.qualityPredictPojo.provinceNotIssued;
        var unloadedNumber= this.qualityPredictPojo.unloadedNumber;
        let carNumber = this.qualityPredictPojo.carNumber;

        if (predictTime ==undefined){
          alert("请选择预测时间");
          throw "";
        }
        if ( predictTimeShift ==undefined){
          alert("请选择预测班次");
          throw "";
        }
        if (future24PredictNumber ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (future12PredictNumber ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (provinceNotIssued ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (unloadedNumber ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (carNumber ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (future24PredictNumber ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (future12PredictNumber ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (provinceNotIssued ==undefined){
          alert("数据有空值");
          throw "";
        }
        if (Number(unloadedNumber) < 0){
          alert("数据有负数");
          throw "";
        }
        if ('' == String(carNumber)){
          alert("数据有空值");
          throw "";
        }
        if (Number(future24PredictNumber) < 0){
          alert("数据有负数");
          throw "";
        }
        if (Number(future12PredictNumber) < 0){
          alert("数据有负数");
          throw "";
        }
        if (Number(provinceNotIssued) < 0){
          alert("数据有负数");
          throw "";
        }
        if (Number(carNumber) < 0){
          alert("数据有负数");
          throw "";
        }

        if (String(carNumber).indexOf('.') != -1) {
          alert("车辆数数据有小数");
          throw "";
        }
        const urls = [];
        this.fileList.forEach(item=>{
          if(item.status ==="success"){
            urls.push(item.response.fileName)
          }
        })
        const data = {
          qualityPredictPojo:this.qualityPredictPojo,
          const:this.const
        }
        addQualityPredict(data).then(es => {
          //console.log(es.code);
          // if(response.code === 200){
          //   this.$router.replace({path:"/qualityPredict/list"});
          // }
          this.msgSuccess("提交成功");
          this.loading = false;
        })
      },
      //文件删除
      handleUploadRemove(file,fileList){
        this.fileList = fileList;
        // console.log(file,fileList)
      },
      //文件状态改变时
      handleUploadChange(file, fileList){
        if(file.status === 'fail'){
          this.msgError('文件上传失败')
        }
        this.fileList = fileList;
        // console.log(file, fileList)
      },
      currentSel(selVal) {
         this.id = selVal.id;
         this.name = selVal.name;
        this.qualityPredictPojo.predictTimeShift = this.name;
        this.qualityPredictPojo.predictTimeShiftId = this.id;
       },
      onInput(){
        this.$forceUpdate();
      },
    },


  };
</script>
